package com.xzm.utils;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;

import java.lang.reflect.Field;
import java.util.List;

/**
 * @author 瞎琢磨先生 https://github.com/xiazuomo/xzm-utils.git
 * @date 2022/7/29 23:51
 */
@Slf4j
public class ObjectUtils {

    public static <T> void isAllFiledNull(List<T> list) {
        if (CollectionUtils.isNotEmpty(list)) {
            T t = list.get(0);
            Field[] fields = t.getClass().getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                try {
                    Object value = field.get(t);
                    if (value != null) {
                        return;
                    }
                } catch (IllegalAccessException e) {
                    log.error("NewExcelUtils.getExcelReader 接口运行异常：", e);
                }
            }
        }
        throw new RuntimeException("请在实体类的成员变量上添加 @Alias 注解一一绑定 Excel 中的字段！");
    }
}
